package com.bw.common.model

import com.bw.common.api.BaseApiService
import com.bw.network.HttpInterceptorType
import com.bw.network.HttpManager
import java.net.HttpCookie

/**
 * 基础数据仓库
 */
abstract class BaseRepository<T:BaseApiService> {
    private var tokenApiServer:T?=null
    private var signApiServer:T?=null
    private var uploadApiServer:T?=null
    private var commonApiServer:T?=null
    fun <T> createApiServer(clazz:Class<T>,type:HttpInterceptorType):T{
        if(HttpInterceptorType.TOKEN==type){
            if(tokenApiServer==null){
                tokenApiServer=HttpManager.createApiServer(clazz,type)
            }
            return tokenApiServer as T
        }
        if(HttpInterceptorType.SIGN==type){
            if(signApiServer==null){
                signApiServer=HttpManager.createApiServer(clazz,type)
            }
            return signApiServer as T
        }
        if(HttpInterceptorType.UPLOAD==type){
            if(uploadApiServer==null){
                uploadApiServer=HttpManager.createApiServer(clazz,type)
            }
            return uploadApiServer as T
        }
        if(HttpInterceptorType.INTERCEPTOR==type){
            if(commonApiServer==null){
                commonApiServer=HttpManager.createApiServer(clazz,type)
            }
            return commonApiServer as T
        }



        return HttpManager.createApiServer(clazz,type) as T
    }
}
